#include"speech_server/RemoteControl.hpp"
#include<QtXml/QXmlStreamReader>
#include<iostream>
#include<QApplication>


RemoteControl::RemoteControl(ComminucationHandler *handler):WorkingThread("RemoteController",handler)
{
}

RemoteControl::~RemoteControl()
{

}

void RemoteControl::run()
{
    exec();
}
void RemoteControl::stop()

{
    quit();
    wait();
}

void RemoteControl::runProgramm()
{
    commitCommand(Run);
}

void RemoteControl::killProgramm()
{
    commitCommand(Kill);
}

void RemoteControl::pingProgramm()
{
    commitCommand(Ping);
}

void RemoteControl::ResetComputer()
{
    commitCommand(ResetPC);
}


void RemoteControl::transmitGrammar(std::string grammarText)
{
    commitCommand(TransmitGramar,grammarText.c_str());
}

void RemoteControl::rollbackGrammar()
{
    commitCommand(RollBackGrammar);
}
void RemoteControl::commitCommand(const RemoteControl::Command c,const char * arg)
{
   QString message=XmlProccessor::generateXmlRemoteMessage(c);
   WorkingThread::commitCommand(getWorkerName(),message);
}
std::string RemoteControl::ParseMessage(std::string msg)
{
    QXmlStreamReader xmlreader(msg.c_str());
    xmlreader.readNextStartElement();
    std::string statusText=xmlreader.readElementText().toStdString();
    return statusText;
}

